#!/usr/bin/env python
# -*- coding:utf-8 -*-


import json
'''
【功能】：读取[{},{},{}...] 列表内嵌字典结构里，每个key的所有值
【入参】：listName-列表名，findItem-要查找的元素名。即key值
【返回值】：在列表里找到的所有值，列表形式返回
'''
def getInfoLD(listName, findItem):
    getValues = []
    for i in range(len(listName)):
        ikeys = list(listName[i].keys())
        if findItem in ikeys:
            getValues.append(listName[i][findItem])
    return getValues

'''
当字典里有bytes类型的数据时，把它转换成str类型。防止使用json.dumps()时报错
'''
def myEncoder(obj):
    """
    只要检查到了是bytes类型的数据就把它转为str类型
    :param obj:
    :return:
    """
    if isinstance(obj, bytes):
        return str(obj, encoding='utf-8')






if __name__ == "__main__":
    listTest =[
      {
        "id": 4,
        "courseName": "白鸽",
        "courseLanguage": "简体中文",
        "openLimit": "中国大陆",
        "coverAddress": "http://test-yuangongzhushou-lixiaoxi.https://oss-cn-beijing.aliyuncs.com/hrssc/uat/sh_entryFile/course_path/20210721/sh_entry-1626860063396-t016d110672c4adb525.jpg",
        "coverName": "t016d110672c4adb525.jpg",
        "courseOrder": 5
      },
      {
        "id": 3,
        "courseName": "像风一样自由",
        "courseLanguage": "简体中文",
        "openLimit": "中国大陆",
        "courseOrder": 4
      },
      {
        "id": 5,
        "courseName": "挪威的森林",
        "courseLanguage": "简体中文",
        "openLimit": "中国大陆",
        "courseOrder": 4
      }
    ]

    # testResult = getInfoLD(listTest,'courseName')
    # print(testResult)

    student = {'name': 'xiaoming', 'age': 11, 'school': 'tsinghua'}
    for key, value in student.items():
        print(key + ':' + str(value))